﻿using System.Collections.Generic;
using System.Web;

namespace mvcfluentcontrols.Controls
{
    public abstract class FluentHtmlString<T> : IHtmlString
    {
        private IDictionary<string, string> _htmlAttributes;
        public IDictionary<string, string> HtmlAttributes
        {
            get { return _htmlAttributes ?? (_htmlAttributes = new Dictionary<string, string>()); }
            set { _htmlAttributes = value; }
        }

        protected FluentHtmlString(string name)
        {            
            AddHtmlAttribute("name", name);
        }

        public T AddHtmlAttribute(string name, string value)
        {
            if (HtmlAttributes.ContainsKey(name))
                HtmlAttributes[name] = value;
            else
                HtmlAttributes.Add(name, value);
            return (T)(object)this;
        }

        public abstract string ToHtmlString();
    }
}